#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" 
@author:zhangxing 
@file: util.py 
@time: 2021/06/26 
"""
import pandas as pd
import os


def block():
    head = ['x0', 'y0', 'x1', 'y1', 'layer_id', 'net_id']
    df = pd.read_csv('D:\\PycharmProjects\\djangoProject\\result\src\\block.csv', names=head)
    # df = df[(df['layer_id'] == "'6-0'") | (df['layer_id'] == "'9-0'") | (df['layer_id'] == "'10-0'") | (
    #         df['layer_id'] == "'11-0'") | (df['layer_id'] == "'12-0'")]
    blocks = df.values.tolist()
    ret = []
    zoom = 2
    for b in blocks:
        b[0] = b[0]
        b[1] = b[1]
        b[2] = (b[2] - b[0])
        b[3] = (b[3] - b[1])
        ret.append(b)
    x_max = max([x[2] for x in blocks])
    x_min = min([x[2] for x in blocks])
    y_max = max([y[3] for y in blocks])
    y_min = min([y[3] for y in blocks])
    a = {
        'block': ret,
        'max_size': [x_max - x_min, y_max - y_min],
        'layer_group': set([b[4] for b in blocks]),
        'net_group': set(b[5] for b in blocks)
    }
    print(a)
    return a


if __name__ == '__main__':
    block()
